
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 10/11/2012 11:28:26
-- Generated from EDMX file: D:\utilisateurs\jbessier-a\Documents\Visual Studio 2012\Projects\LiveLocation\LiveLocation\Models\LiveLocationEntities.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [LiveLocation];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_IdentityTracks]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TracksSet] DROP CONSTRAINT [FK_IdentityTracks];
GO
IF OBJECT_ID(N'[dbo].[FK_TracksCoordinates]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CoordinatesSet] DROP CONSTRAINT [FK_TracksCoordinates];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[CoordinatesSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CoordinatesSet];
GO
IF OBJECT_ID(N'[dbo].[IdentitySet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[IdentitySet];
GO
IF OBJECT_ID(N'[dbo].[TracksSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TracksSet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'CoordinatesSets'
CREATE TABLE [dbo].[CoordinatesSets] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Track_Id] int  NOT NULL,
    [lat] float  NOT NULL,
    [long] float  NOT NULL
);
GO

-- Creating table 'IdentitySets'
CREATE TABLE [dbo].[IdentitySets] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [PhoneId] nvarchar(max)  NOT NULL,
    [UserName] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'TracksSets'
CREATE TABLE [dbo].[TracksSets] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [TrackName] nvarchar(max)  NOT NULL,
    [TrackDate] datetime  NOT NULL,
    [Identity_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'CoordinatesSets'
ALTER TABLE [dbo].[CoordinatesSets]
ADD CONSTRAINT [PK_CoordinatesSets]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'IdentitySets'
ALTER TABLE [dbo].[IdentitySets]
ADD CONSTRAINT [PK_IdentitySets]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TracksSets'
ALTER TABLE [dbo].[TracksSets]
ADD CONSTRAINT [PK_TracksSets]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Track_Id] in table 'CoordinatesSets'
ALTER TABLE [dbo].[CoordinatesSets]
ADD CONSTRAINT [FK_TracksCoordinates]
    FOREIGN KEY ([Track_Id])
    REFERENCES [dbo].[TracksSets]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TracksCoordinates'
CREATE INDEX [IX_FK_TracksCoordinates]
ON [dbo].[CoordinatesSets]
    ([Track_Id]);
GO

-- Creating foreign key on [Identity_Id] in table 'TracksSets'
ALTER TABLE [dbo].[TracksSets]
ADD CONSTRAINT [FK_IdentityTracks]
    FOREIGN KEY ([Identity_Id])
    REFERENCES [dbo].[IdentitySets]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_IdentityTracks'
CREATE INDEX [IX_FK_IdentityTracks]
ON [dbo].[TracksSets]
    ([Identity_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------